package hluck.me.srorage.sys.common;

import java.util.ArrayList;
import java.util.List;

public class TreeNodeBuilder {

    /**
     * 把没有层级关系的集合变成有层级关系
     */
    public static List<TreeNode> build(List<TreeNode> treeNodes,Integer topId){
        ArrayList<TreeNode> list = new ArrayList<>();
        for (TreeNode treeNode : treeNodes) {
            if (treeNode.getPid()==topId){
                list.add(treeNode);
            }
            for (TreeNode node : treeNodes) {
                if (treeNode.getId()==node.getPid()){
                    treeNode.getChildren().add(node);
                }
            }
        }
        return list;
    }
}
